<?php
/*
Template Name: Profil
*/
?>

<?php get_header() ?>

<?php


//test commit

//$userid = get_current_user_id();
if ($_GET['id']){
	$userid =htmlspecialchars($_GET['id']);
}
else {
	$userid = get_current_user_id();
}


$user = get_user_meta($userid);
$wpuser= get_userdata($userid);
//var_dump($user);
//var_dump($wpuser);


?>

<div class="middle-highlight-container">
  <div class="middle">
    <h2 class="page-subtitle-profil"><?php if($user['first_name'][0] != "") :
	        	echo $user['first_name'][0].' '.$user['last_name'][0];
	        	else : echo "Profil";
	        	endif; ?></h2>
  </div>
</div>

<div id="content-container">

  <div id="content">
    <?php the_post()?>
    <div id="post-<?php the_ID(); ?>" class="post">
      <div class="post-content">

        <div class="profil_avatar">
				<?php if($user['simple_local_avatar'][0]!='') : echo get_avatar($userid);
				  else : echo '<img id="test" src="'. get_bloginfo('template_url'). '/images/profil.png"/>';
				  endif;?>
				<div class="modifier">
					<?php if(get_current_user_id() == 1) : ?>
							<a href="<?php bloginfo('url'); ?>/profil-modification?id=<?php echo $wpuser->ID; ?>" title="Modifier"> Modifier le profil</a>	
					<?php elseif (get_current_user_id() == $wpuser->ID ) : ?>
						<a href='<?php bloginfo('url'); ?>/profil-modification' Title='Modifier'/> Modifier mon profil</a>
					<?php endif;?>

				</div>
        </div>

       	<div class="profil_infos">

		<div>
	        <label> Promotion : <div class="profil_info_element"><?php if($user['promo'][0] != "") :
	        	echo $user['promo'][0];
	        	else : echo "N/A";
	        	endif;?>
	        	</div>
	        </label>
	        <label> Formation : <div class="profil_info_element"><?php if($user['formation'][0] != "") :
	        	echo $user['formation'][0];
	        	else : echo "N/A";
	        	endif;?>
	        	</div>
	        </label>
	        <label>T&eacutel&eacutephone : <div class="profil_info_element"><?php if($user['tel'][0] != "") :
	        	echo $user['tel'][0];
	        	else : echo "N/A";
	        	endif;?>
	        	</div>
	        </label>
        </div>
		<div>
	        <label>Statut : <div class="profil_info_element"> <?php if($user['statut'][0] != "") :
	        	echo $user['statut'][0];
	        	else : echo "N/A";
	        	endif;?>
	        	</div>
	        </label>
		</div>
		<div>
        	<label>Email : <div class="profil_info_element"> <?php echo $wpuser->user_email ?> </div></label>
        </div>
        <div>
	      	<label> Site internet : <div class="profil_info_element">
	      	<?php if($wpuser->user_url != "") :
	      	?>
	      	<a href="<?php echo $wpuser->user_url; ?>" title="Site internet"><?php echo $wpuser->user_url; ?></a>
			<?php else : echo "N/A";
	        	endif;?>
	        	</div>
	        </label>
	    </div>

	    </div>
		<div class="profil_contacter">
	   		<div class="contact">
					<a href="mailto:<?php echo $wpuser->user_email?>" title="Contact">
					<div class="contact-icon">
						<img src="<?php bloginfo('template_url');?>/images/contact.png" alt="" class="get-in-touch">
					</div>
					<span class="contact-text">
						Contacter
					</span>
					</a>
			</div>
		</div>


        <div class="profil_titre_bloc"> Informations professionnelles
        <a href="<?php echo $user['viadeo'][0]?>"> <img class="profil_bloc_viadeo" src="<?php bloginfo('template_url') ;?>/images/viadeo-logo.png"/></a>
        <a href="<?php echo $user['linkedin'][0]?>"> <img class="profil_bloc_linkedin" src="<?php bloginfo('template_url') ;?>/images/linkedin-logo.png"/></a>
		</div>

        <div class="profil_bloc_g">
				<div class="profil_bloc_entre">
					<label class="profil_bloc_titre"> Entreprise Actuelle  </label><p>
		  	      <?php if($user['ent_actuelle'][0] != "") :
		   	     	echo $user['ent_actuelle'][0];
		   	     	else : echo "N/A";
		  	      	endif;?>
		  	      	</p>

				</div>
				<div class="profil_bloc_poste">
		  	      <label class="profil_bloc_titre"> Poste  </label><p>
		  	      <?php if($user['poste'][0] != "") :
		  	      	echo $user['poste'][0];
		  	      	else : echo "N/A";
		  	      	endif;?>
					</p>
			   </div>
		 	   <div class="profil_bloc_mission">
			        <label class="profil_bloc_titre"> Mission  </label><p>
		  	      <?php if($user['mission'][0] != "") :
		  	      	echo $user['mission'][0];
		  	      	else : echo "N/A";
		  	      	endif;?>
		  	      	</p>

		 	   </div>
		 	   <div class="profil_bloc_descriptif">
		 	       <label class="profil_bloc_titre"> Descriptif  </label><p>
			        <?php if($user['desc_ent'][0] != "") :
			        	echo $user['desc_ent'][0];
			        	else : echo "N/A";
			        	endif;?>
			        	</p>

			   </div>

		</div>
	<div class="profil_titre_bloc">
		<label>Actualit&eacute(s) r&eacutecente(s)</label>
	</div>


	 <div class="profil_actu">
        	<?php query_posts("&post_type=post&author=$userid&showposts=10&orderby=date&order=DESC");?>
        	<?php if ( have_posts() ) : ?>
				<?php while ( have_posts() ) : the_post(); ?>
           		<h4><a href="<?php the_permalink(); ?>" title="Accéder à la page <?php the_title(); ?>"><?php the_title(); ?></a></h4>
				<?php the_excerpt(); ?>
				<?php endwhile; ?>
				<?php wp_reset_query();?>
			<?php else : ?>
				<p> Pas d'actualité recente</p>
			<?php endif; ?>
        </div>
       </div>
	</div>
  </div><!-- #content -->

</div><!-- #content-container -->



<?php get_footer() ?>
